<?php
require_once('../model/class.ads.php');
$qiAds = new qiAds($DB);

if($ts == 'list')
{
$ads = $qiAds->getAds();
}

if($ts == 'add')
{
$adName = isset($_POST['name']) ? $_POST['name'] : '';
$adContent = isset($_POST['content']) ? $_POST['content'] : '';
if(!empty($adName)){
$qiAds->addAds($adName,$adContent);
header("Location: index.php?action=ads&ts=list");
}
}

if($ts == 'edit')
{
$aid = isset($_GET['id']) ? $_GET['id'] : '';
$adDate = $qiAds->getOneAds($aid);
}

if($ts=='update')
{
$adName = isset($_POST['name']) ? $_POST['name'] : '';
$adContent = isset($_POST['content']) ? $_POST['content'] : '';
$aid = isset($_GET['id']) ? intval($_GET['id']) : '';

$adDate = array(
'name' => $adName,
'content' => $adContent
);

$qiAds->updateAds($adDate,$aid);

header("Location: index.php?action=ads&ts=list");
}

if($ts == 'del')
{
$adsId = isset($_GET['id']) ? $_GET['id'] : '';
$qiAds->deleteAds($adsId);
header("Location: index.php?action=ads&ts=list");
}

?>